package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.admin.utils.RegexUtil;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.Throw;
import com.cq.hd.member.api.TbBusinessPointsMallApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "积分商城相关接口")
@Slf4j
@RestController
@RequestMapping("/businessPointsMall")
public class TbBusinessPointsMallController extends BaseController {

    @Autowired
    private TbBusinessPointsMallApi mallApi;

    @ApiOperation(value = "积分商家列表")
    @ApiImplicitParam(name = "businessPointsMallPageDto", value = "实体", paramType = "query", dataType = "BusinessPointsMallPageDto")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
//    @RequiresPermissions("business:business:list")
    @RequiresPermissionsDesc(menu = {"积分管理", "积分商家"}, button = "查询")
    @GetMapping("/pageBusiness")
    public Result<Page<BusinessPointsMallPageVo>> pageBusiness(BusinessPointsMallPageDto businessPointsMallPageDto) {
        return mallApi.pageBusiness(businessPointsMallPageDto);
    }

    @ApiOperation(value = "积分商家积分商品列表")
    @ApiImplicitParam(name = "businessPointsMallProductPageDto", value = "实体", paramType = "query", dataType = "BusinessPointsMallProductPageDto")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
//    @RequiresPermissions("business:business:list")
    @RequiresPermissionsDesc(menu = {"积分管理", "商家积分商品"}, button = "查询")
    @GetMapping("/pageProducts")
    public Result<Page<BusinessPointsMallProductPageVo>> pageProducts(BusinessPointsMallProductPageDto businessPointsMallProductPageDto) {
        Long businessId = businessPointsMallProductPageDto.getBusinessId();
        if (businessId == null || businessId == 0) {
            Throw.isBusinessException("商家id不能为空");
        }
        return mallApi.pageProducts(businessPointsMallProductPageDto);
    }

    @ApiOperation(value = "用户积分明细")
    @ApiImplicitParam(name = "businessPointsMallProductPageDto", value = "实体", paramType = "query", dataType = "BusinessPointsMallProductPageDto")
    @ApiResponse(response = BusinessPageVo.class, code = 200, message = "接口返回对象参数")
//    @RequiresPermissions("business:business:list")
    @RequiresPermissionsDesc(menu = {"积分管理", "商家积分商品"}, button = "查询")
    @GetMapping("/pageUserPointsDetail")
    public Result<Page<AdminUserPointsDetailPageVo>> pageUserPointsDetail(AdminUserPointsDetailPageDto adminUserPointsDetailPageDto) {
        String userKeyword = adminUserPointsDetailPageDto.getUserKeyword();
        if (userKeyword != null) {
            if (RegexUtil.isMobileSimple(userKeyword)) {
                adminUserPointsDetailPageDto.setMobile(userKeyword);
            } else {
                adminUserPointsDetailPageDto.setNickName(userKeyword);
            }
        }
        return mallApi.adminPageUserPointsDetail(adminUserPointsDetailPageDto);
    }
}
